package com.fand.manager.service.impl;

import java.util.concurrent.TimeUnit;

import com.anji.captcha.service.CaptchaCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * 验证码服务类
 *
 * Author: zhangjiabin
 * Email: javaboyok@163.com
 * CreateDate: 2021/6/20
 * Version: 1.0
 */
public class CaptchaCacheServiceRedisImpl implements CaptchaCacheService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void set(String key, String value, long expiresInSeconds) {
        redisTemplate.opsForValue().set(key, value, expiresInSeconds, TimeUnit.SECONDS);
    }

    @Override
    public boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }

    @Override
    public void delete(String key) {
        redisTemplate.delete(key);
    }

    @Override
    public String get(String key) {
        return (String)redisTemplate.opsForValue().get(key);
    }

    @Override
    public Long increment(String key, long val) {
        return redisTemplate.opsForValue().increment(key,val);
    }

    @Override
    public String type() {
        return "redis";
    }
}
